//判断字符串是否为空
function isEmpty(strVal) {
    if (strVal == '' || strVal == null || strVal == undefined) {
        return true;
    } else {
        return false;
    }
}

function validate_username(){
	var value = $("#username").val();
    if(isEmpty(value) || value.length < 2){
    	$("#err-username").html("店铺名称格式不正确");
        return false;
    }else{
    	$("#err-username").html("");
        return true;
    }
}

function validate_lasttotalsale(){
	var value = $("#lastTotalSale").val();
	var pattern = /^([0-9]*\.?[0-9]*)$/
	if(isEmpty(value) || !pattern.test(value)){
    	$("#err-lasttotalsale").html("销售额格式不正确");
        return false;
    }else{
    	$("#err-lasttotalsale").html("");
        return true;
    }
}

function validate_lastjlr(){
	var value = $("#lastJLR").val();
	var pattern = /^([0-9]*\.?[0-9]*)$/
	if(!isEmpty(value) && !pattern.test(value)){
    	$("#err-lastjlr").html("销售额格式不正确");
        return false;
    }else{
    	$("#err-lastjlr").html("");
        return true;
    }
}

function validate_lastmll(){
	var value = $("#lastMLL").val();
	var pattern = /^([0-9]*\.?[0-9]*)$/
	if(!isEmpty(value) && !pattern.test(value)){
    	$("#err-lastmll").html("毛利率格式不正确");
        return false;
    }else{
    	$("#err-lastmll").html("");
        return true;
    }
}

function validate_lastggtfb(){
	var value = $("#lastGGTFB").val();
	var pattern = /^([0-9]*\.?[0-9]*)$/
	if(!isEmpty(value) && !pattern.test(value)){
    	$("#err-lastggtfb").html("广告投放比格式不正确");
        return false;
    }else{
    	$("#err-lastggtfb").html("");
        return true;
    }
}

function checkInput(){
	if(!validate_username() || !validate_lasttotalsale()
			|| !validate_lastjlr() || !validate_lastmll() || !validate_lastggtfb()){
		return false;
	}
	return true;
}

function evaluateShop(){
	if(checkInput()){
		var shopname = $("#username").val();
		var lasttotalsale = $("#lastTotalSale").val();
		var lastjlr = $("#lastJLR").val();
		var lastmll = $("#lastMLL").val();
		var lastggtfb = $("#lastGGTFB").val();
		
		var pdata = {"shopname":shopname,"lasttotalsale":lasttotalsale,"lastljr":lastjlr,"lastmll":lastmll,"lastggtfb":lastggtfb};
		console.log(pdata);
		$.ajax({
			url: "../shopValue/evaluate",
			data: JSON.stringify(pdata),
			contentType: "application/json",
			dataType: 'json',
			type: "POST",
			success: function (result) { 
				console.log(result);
				if(result.status == 200){
				    zeroModal.success({
				    	content: '店铺价值预估为<span style="color:rgb(241,49,49);font-size:26px;">'+result.data+'</span>万元',
			            contentDetail: '赶紧申请贷款吧~',
			            okFn: function() {
			            	window.location = location;
			            }
				    });
				}else{
					zeroModal.error({
				    	content: result.data,
			            contentDetail: '谢谢您的配合~'
				    });
				}
	        }
		});
	}
}